package ru.spbau.database.group3.parser;

import java.util.ArrayList;

/**
 * Created with IntelliJ IDEA.
 * User: stas
 * Date: 1/27/13
 * Time: 1:47 PM
 */
public final class StringConstants {
    public static final String SELECT = "SELECT";
    public static final String CREATE_TABLE = "CREATE TABLE";
    public static final String CREATE_INDEX = "CREATE INDEX";
    public static final String CREATE_UNIQUE_INDEX = "CREATE UNIQUE INDEX";
    public static final String INSERT = "INSERT INTO";
    public static final String UPDATE = "UPDATE TABLE";
    public static final String DELETE = "DELETE FROM";


    public static final String FROM = "FROM";
    public static final String WHERE = "WHERE";
    public static final String VALUES = "VALUES";
    public static final String SET = "SET";
    public static final String USING = "USING";
    public static final String BTREE = "BTREE";
    public static final String HASH = "HASH";
    public static final String ON = "ON";
    public static final String ASC = "ASC";
    public static final String DESC = "DESC";

    public static final String GT = ">";
    public static final String LT = "<";
    public static final String EQ = "=";
    public static final String NEQ = "<>";
    public static final String GEQ = ">=";
    public static final String LEQ = "<=";

    public static final String[] CTS = {NEQ, GEQ, LEQ, GT, LT, EQ};

    public static boolean isName(String s) {
        return !s.equals("");
    }

    public static boolean isNames(ArrayList<String> names) {
        for(String s : names) {
            if(!isName(s)) {
                return false;
            }
        }
        return true;
    }

    public static boolean isTypes(ArrayList<String> types) {
        for(String s : types) {
            if(!isType(s)) {
                return false;
            }
        }
        return true;
    }

    private static boolean isType(String s) {
        return s.equals("INT") || s.equals("DOUBLE") || s.matches("VARCHAR[(][0-9]+[)]");
    }

    public static boolean isOrders(ArrayList<String> orders) {
        for(String s : orders) {
            if(!isOrder(s)) {
                return false;
            }
        }
        return true;
    }

    private static boolean isOrder(String s) {
        return s.equals(ASC) || s.equals(DESC);
    }

    public static boolean isIndexType(String type) {
        return type.equals(BTREE) || type.equals(HASH);
    }
}
